package com.yanqu.road.server.logic.activity.eggs;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;
import java.util.List;

public class PaintedEggsEventCondition extends BaseActivityCondition {
    public PaintedEggsEventCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        List<BigInteger> paramList = activityConditionInfo.getParamList();
        //天数
        int dayNum = paramList.get(0).intValue();
        ActivityInfo curActivity = NormalActivityMgr.getActivityInfo(activityInfo.getActivityId());
        long zeroTime = DateHelper.getZeroTimeStamp(curActivity.getBeginTime()*1000);
        long disTime = System.currentTimeMillis() - zeroTime;
        long days = disTime / (24 * 60 * 60 * 1000) + 1;
        if(days == dayNum){
            setValue(BigInteger.valueOf(dayNum));
        }
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        List<BigInteger> paramList = activityConditionInfo.getParamList();
        //天数
        int dayNum = paramList.get(0).intValue();
        return getValue().intValue() == dayNum;
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.PaintedEggsEvent.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.PaintedEggsEvent.getValue(), handle);
    }
}
